package com.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.context.Application;
import com.context.SpringContainer;

/**
 * @author zyl
 *
 */
public class ApplicationContextListener implements ServletContextListener {

        public void contextInitialized(ServletContextEvent event) {
            try {
                ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());

                SpringContainer container = new SpringContainer();
                container.setApplicationContext(applicationContext);
                Application.getInstance().setContainer(container);
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }

        public void contextDestroyed(ServletContextEvent arg0) {

        }


}
